package com.mryang.ladder;

import java.util.Scanner;

/**
 * @ClassName testSeatNumber
 * @Description TODO 考试座位号
 * @Author Genius
 * @Date 2021/1/19 18:02
 */
public class testSeatNumber {
    public static void main(String[] args) {
        Scanner scr = new Scanner(System.in);
        int number = scr.nextInt();
        // 数组及初始化
        long[][] seatNumber = new long[number][3];
        for (int i = 0; i < number; i++) {
            for (int j = 0; j < 3; j++) {
                seatNumber[i][j] = scr.nextLong();
            }
        }
        // 查找元素
        int count = scr.nextInt();
        int[] insertNumber= new int[count];
        for (int i = 0; i < count; i++) {
            insertNumber[i] = scr.nextInt();
        }
        // 查询
        for(int i = 0;i<count;i++){
            for (int j = 0; j < number; j++) {
                if(insertNumber[i]==seatNumber[j][1]){
                    System.out.println(seatNumber[j][0] + " "+seatNumber[j][2]);
                }
            }
        }
    }
}
